//
//  DiaryBannerCell.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/8/23.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "DiaryBannerCell.h"
#import "DiaryActivityModel.h"
@interface DiaryBannerCell ()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *commendLabel;//评论
@property (nonatomic, strong) UIImageView *aImage;
@end

@implementation DiaryBannerCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        for(int i = 0; i < 3; i++)
        {
//            DiaryActivityModel *model = self.activityArray[i];
            _imgView = [[UIImageView alloc] initWithFrame:CGRectMake( (self.scrollView.frame.size.width - 100) * i + 5 , 0, CGRectGetWidth(self.scrollView.bounds) - 100 - 5, 200)];
//            [_imgView sd_setImageWithURL:[NSURL URLWithString:STRING(model.topic_logo)] placeholderImage:nil];
            _imgView.userInteractionEnabled = YES;
            _imgView.tag = 1000 + i + 1;
            
            if(_imgView.tag == 1001)
            {
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAction:)];
                [_imgView addGestureRecognizer:tap];
            }
            else if (_imgView.tag == 1002)
            {
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAction:)];
                [_imgView addGestureRecognizer:tap];
            }
            else
            {
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAction:)];
                [_imgView addGestureRecognizer:tap];
            }
            [self.scrollView addSubview:_imgView];
            _titleLabel =[[UILabel alloc] initWithFrame:CGRectMake( (self.scrollView.frame.size.width - 100) * i, 200 + 15, CGRectGetWidth(self.scrollView.bounds) - 100, 25)];
//            _titleLabel.text = model.topic_title;
            _titleLabel.tag = 2222 + i;
            _titleLabel.textColor = ColorFrom16(0x202020);
            _titleLabel.font = PFMFONT(18);
            _titleLabel.textAlignment = 1;
            _titleLabel.adjustsFontSizeToFitWidth = YES;
            [self.scrollView addSubview:_titleLabel];
            
            [self.scrollView removeFromSuperview];
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake( (self.scrollView.frame.size.width - 100) * i, 200 + 15 + 25 + 12, CGRectGetWidth(self.scrollView.bounds) - 100, 17)];
            [self.scrollView addSubview:view];
//            self.scrollView.delegate = self;
            if(IS_IPHONE5)
            {
                _aImage = [[UIImageView alloc] initWithFrame:CGRectMake(30, 0, 65, 17)];
            }
            else
            {
                _aImage = [[UIImageView alloc] initWithFrame:CGRectMake(76, 0, 65, 17)];
            }
            _aImage.image = IMAGE(@"diary_new.jpg");
            [view addSubview:_aImage];
            
            if(IS_IPHONE5)
            {
                _commendLabel = [[UILabel alloc] initWithFrame:CGRectMake(30 + 65 + 5 , 0, 68, 17)];
            }
            else
            {
                _commendLabel = [[UILabel alloc] initWithFrame:CGRectMake(76 + 65 + 5 , 0, 68, 17)];
            }
//            _commendLabel.text = [NSString stringWithFormat:@"%@条点评", model.topic_sum_comment];
            _commendLabel.tag = 3333 + i;
            _commendLabel.textColor = ColorFrom16(0x323232);
            _commendLabel.font = PFRFONT(12);
            [view addSubview:_commendLabel];
        }
        [self addSubview:self.scrollView];
        
    }
    return self;
}


- (UIScrollView *)scrollView
{
    if(!_scrollView)
    {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, GWIDTH - 1, 300)];
        _scrollView.contentSize = CGSizeMake((GWIDTH - 100) * 3, 300);
        _scrollView.contentOffset = CGPointMake((GWIDTH - 150) , 0);//CGRectGetWidth(scrollView.bounds) * 2 是设置默认为第几个视图
        _scrollView.showsHorizontalScrollIndicator = NO;

    }
    return _scrollView;
}

- (void)handleTapAction:(UITapGestureRecognizer *)tap
{
    
    if(tap.view.tag == 1001)
    {
        DiaryActivityModel *model = self.array[0];
        [GW_webView handleWebView:[NSString stringWithFormat:@"%@/diary/rijiDP.html?gid=%@", GW_Domain,model.id] viewController:self.viewController titleName:nil goodid:model.id];
    }
    else if(tap.view.tag == 1002)
    {
        DiaryActivityModel *model = self.array[1];
        [GW_webView handleWebView:[NSString stringWithFormat:@"%@/diary/rijiDP.html?gid=%@",  GW_Domain,model.id] viewController:self.viewController titleName:nil goodid:model.id];
    }
    else
    {
        DiaryActivityModel *model = self.array[2];
        [GW_webView handleWebView:[NSString stringWithFormat:@"%@/diary/rijiDP.html?gid=%@", GW_Domain,model.id] viewController:self.viewController titleName:nil goodid:model.id];
    }
}
- (void)configView
{
    for(int i = 0; i < self.array.count; i++)
    {
        UILabel *title = [self viewWithTag:2222+i];
        UILabel *comment = [self viewWithTag:3333+i];
        UIImageView *iv = [self viewWithTag:1001+i];
        DiaryActivityModel *model = self.array[i];
        [iv sd_setImageWithURL:[NSURL URLWithString:model.topic_logo] placeholderImage:IMAGE(@"jia_default")];
        title.text = model.topic_title;
        comment.text = [NSString stringWithFormat:@"%@条点评", model.topic_sum_comment];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
